//
//  XOWMBindView.m
//  XOWMSDK
//
//  Created by skyline on 2018/7/27.
//  Copyright © 2018年 skyline. All rights reserved.
//

#import "XOWMBindView.h"
@interface XOWMBindView ()<YJDTextFieldDelegate>

@end
@implementation XOWMBindView
- (XOWMButton *)titleIMG
{
    if (!_titleIMG)
    {
        _titleIMG = [[XOWMButton alloc] init];
        _titleIMG.height = TITLE_HEIGHT;
        _titleIMG.style = YJDButtonTitleStyleCameo;
        _titleIMG.userInteractionEnabled = NO;
        [self addSubview:_titleIMG];
        _titleIMG.c_centerX.equal(self);
        _titleIMG.c_centerY.equal(self);
        _titleIMG.c_size.equal(CGSizeMake(70, TITLE_HEIGHT));
    }
    return _titleIMG;
}

- (XOWMTextField *)phoneTF
{
    if (!_phoneTF)
    {
        _phoneTF = [[XOWMTextField alloc] init];
        _phoneTF.type = YJDTextFieldTypePhoneNumber;
        _phoneTF.returnKeyType = UIReturnKeyNext;
        _phoneTF.customDelegate = self;
        [self addSubview:_phoneTF];
        _phoneTF.c_centerX.equal(self);
        _phoneTF.c_size.equal(CGSizeMake(self.bounds.size.width - GAP * 2, TEXTFILDHEIGHT));
        if ([XOWMHelper shareHelp].style == XOWMPlatformStyleImage)
            _phoneTF.c_top.equal(self).with.coffset(GAP * 3.0 + BACKBUTTON_HEIGHT);
                else
                    _phoneTF.c_top.equal(self).with.coffset(GAP * 3.0 + BACKBUTTON_HEIGHT);
    }
    return _phoneTF;
}

- (XOWMTextField *)verifyTF
{
    if (!_verifyTF)
    {
        _verifyTF = [[XOWMTextField alloc] init];
        _verifyTF.type = YJDTextFieldTypeVerify;
        _verifyTF.customDelegate = self;
        [self addSubview:_verifyTF];
        _verifyTF.c_top.equal(self.phoneTF.c_bottom).with.coffset(GAP * 2.0);
        _verifyTF.c_centerX.equal(self);
        _verifyTF.c_size.equal(CGSizeMake(self.bounds.size.width - GAP * 2.0, TEXTFILDHEIGHT));
    }
    return _verifyTF;
}

- (XOWMButton *)ignoreBtn
{
    if (!_ignoreBtn)
    {
        _ignoreBtn= [[XOWMButton alloc] init];
        _ignoreBtn.height = TEXTFILDHEIGHT;
        [_ignoreBtn addTarget:self action:@selector(yjd_actionForIgnoreButton) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_ignoreBtn];
        _ignoreBtn.c_left.equal(self).with.coffset(GAP);
        _ignoreBtn.c_top.equal(self.verifyTF.c_bottom).with.coffset(GAP * 2.0);
        _ignoreBtn.c_size.equal(CGSizeMake((self.bounds.size.width - GAP * 3.0) / 3.0 * 2.0, BUTTONHEIGHT));
    }
    return _ignoreBtn;
}

- (XOWMButton *)bindBtn
{
    if (!_bindBtn)
    {
        _bindBtn= [[XOWMButton alloc] init];
        _bindBtn.height = TEXTFILDHEIGHT;
        [_bindBtn addTarget:self action:@selector(yjd_actionForBindButton) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_bindBtn];
        _bindBtn.c_right.equal(self).with.coffset(-GAP);
        _bindBtn.c_centerY.equal(self.ignoreBtn);
        _bindBtn.c_size.equal(CGSizeMake((self.bounds.size.width - GAP * 3.0) / 3.0, BUTTONHEIGHT));
    }
    return _bindBtn;
}

- (void)yjd_actionForIgnoreButton
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(yjd_actionForYJDBindViewWithEvent:dict:)])
    {
        [self.delegate yjd_actionForYJDBindViewWithEvent:YJDBindViewEventIgnore dict:nil];
    }
}

- (void)yjd_actionForBindButton
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(yjd_actionForYJDBindViewWithEvent:dict:)])
    {
        [self.delegate yjd_actionForYJDBindViewWithEvent:YJDBindViewEventBind dict:@{@"phone":self.phoneTF.text}];
    }
}

#pragma mark - YJDTextFieldDelegate
- (BOOL)yjd_actionForVerifyCode
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(yjd_actionForYJDBindViewWithEvent:dict:)])
    {
        [self.delegate yjd_actionForYJDBindViewWithEvent:YJDBindViewEventVerify dict:@{@"phone":self.phoneTF.text}];
        return ([self.phoneTF.text yjd_isMobile])?YES:NO;
    }
    return NO;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (textField.returnKeyType == UIReturnKeyNext)
    {
        [self.verifyTF becomeFirstResponder];
        return NO;
    }
    return YES;
}
/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */


- (void)sp_getLoginState {
    NSLog(@"Get Info Success");
}
@end
